// 专家首页
//  MZY_ExpertViewController.m
//  FullHouse
//
//  Created by dllo on 16/1/15.
//  Copyright © 2016年 yy. All rights reserved.
//

#import "MZY_ExpertViewController.h"
#import "NetworkingTool.h"
#import "UIImageView+WebCache.h"
#import "MZY_DesignerCell.h"
#import "MZY_worksCell.h"
#import "MZY_designerModel.h"
#import "MZY_worksModel.h"
#import "MBProgressHUD.h"
#import "MZY_ForemanCell.h"
#import "MZY_ProjectCell.h"
#import "MZY_WithoutPicture.h"
#import "MZY_EX_designerViewController.h"
#import "MZY_EX_projectViewController.h"
#import "MZY_EX_foremanViewController.h"
#import "MZY_EX_workViewController.h"
#import "MJRefresh.h"
#import "MZY_City.h"

#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
#define HORIZONTAL [UIScreen mainScreen].bounds.size.width / 414
#define VERTICAL [UIScreen mainScreen].bounds.size.height / 736

@interface MZY_ExpertViewController ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate,MZY_CityDelegate>

@property(nonatomic, retain)UIButton *designerButton;
@property(nonatomic, retain)UIButton *worksButton;
@property(nonatomic, retain)UIScrollView *scrollView;
@property(nonatomic, retain)UITableView *leftTableView;
@property(nonatomic, retain)NSMutableArray *leftArr;
@property(nonatomic, retain)UITableView *rightTableView;
@property(nonatomic, retain)NSMutableArray *rightArr;
@property(nonatomic, retain)UIView *foremanView;
@property(nonatomic, assign)BOOL isDesigner;
@property(nonatomic, retain)UIButton *foremanButton;
@property(nonatomic, retain)UIButton *projectButton;
@property(nonatomic, retain)UIScrollView *foremanScrollView;
@property(nonatomic, retain)UITableView *foremanTableView;
@property(nonatomic, retain)NSMutableArray *foremanArr;
@property(nonatomic, retain)UITableView *projectTableView;
@property(nonatomic, retain)NSMutableArray *projectArr;
@property(nonatomic, retain)MBProgressHUD *hud;
@property(nonatomic, assign)NSInteger pageOne;
@property(nonatomic, assign)NSInteger pageTwo;
@property(nonatomic, assign)NSInteger pageThree;
@property(nonatomic, assign)NSInteger pageFour;
@property(nonatomic, retain)NSString *idStr;
@property(nonatomic, retain)UIButton *leftButton;

@end

@implementation MZY_ExpertViewController

- (void)dealloc
{
    [self.designerButton release];
    [self.worksButton release];
    [self.scrollView release];
    [self.leftTableView release];
    [self.leftArr release];
    [self.rightTableView release];
    [self.rightArr release];
    [self.foremanView release];
    [self.foremanButton release];
    [self.projectButton release];
    [self.foremanScrollView release];
    [self.foremanTableView release];
    [self.foremanArr release];
    [self.projectTableView release];
    [self.projectArr release];
    [self.hud release];
    [self.idStr release];
    [self.leftButton release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor cyanColor];
    [self createView];
    [self createData];
}

#pragma mark 获取数据
- (void)createData{
    NSString *str1 = [NSString stringWithFormat:@"http://api.meilijia.com/app/advanced_pro_list?page=1&zone=%@",self.idStr];
    [NetworkingTool networkingWithStrURL:str1 type:GETType bodyStr:nil block:^(id result) {
        self.leftArr = [NSMutableArray array];
        for (NSDictionary *temp in result[@"data"][@"advanced_pro_list"][@"list"]) {
            MZY_designerModel *designer = [[MZY_designerModel alloc]init];
            [designer setValuesForKeysWithDictionary:temp];
            [self.leftArr addObject:designer];
            [designer release];
        }
        [self.leftTableView reloadData];
        self.hud.hidden = YES;
    }];
    NSString *str2 = [NSString stringWithFormat:@"http://api.meilijia.com/app/work_list?page=1&city_id=%@",self.idStr];
    [NetworkingTool networkingWithStrURL:str2 type:GETType bodyStr:nil block:^(id result) {
        self.rightArr = [NSMutableArray array];
        for (NSDictionary *temp in result[@"data"][@"work_list"][@"collections"]) {
            MZY_worksModel *works = [[MZY_worksModel alloc]init];
            [works setValuesForKeysWithDictionary:temp];
            [self.rightArr addObject:works];
            [works release];
        }
        [self.rightTableView reloadData];
    }];
    NSString *str3 = [NSString stringWithFormat:@"http://api.meilijia.com/app/advanced_pro_gz_list?page=1&zone=%@",self.idStr];
    [NetworkingTool networkingWithStrURL:str3 type:GETType bodyStr:nil block:^(id result) {
        self.foremanArr = [NSMutableArray array];
        for (NSDictionary *temp in result[@"data"][@"advanced_pro_gz_list"][@"list"]) {
            MZY_designerModel *designer = [[MZY_designerModel alloc]init];
            [designer setValuesForKeysWithDictionary:temp];
            [self.foremanArr addObject:designer];
            [designer release];
            [self.foremanTableView reloadData];
        }
    }];
    NSString *str4 = [NSString stringWithFormat:@"http://api.meilijia.com/app/pro_gz_work_list?page=1&city_id=%@",self.idStr];
    [NetworkingTool networkingWithStrURL:str4 type:GETType bodyStr:nil block:^(id result) {
        self.projectArr = [NSMutableArray array];
        for (NSDictionary *temp in result[@"data"][@"pro_gz_work_list"][@"collections"]) {
            MZY_worksModel *works = [[MZY_worksModel alloc]init];
            [works setValuesForKeysWithDictionary:temp];
            [self.projectArr addObject:works];
            [works release];
        }
        [self.projectTableView reloadData];
    }];
}

#pragma mark 加载数据
- (void)loadData{
    NSString *strL = [NSString stringWithFormat:@"http://api.meilijia.com/app/advanced_pro_list?page=%ld&zone=%@",self.pageOne ++,self.idStr];
    [NetworkingTool networkingWithStrURL:strL type:GETType bodyStr:nil block:^(id result) {
        for (NSDictionary *temp in result[@"data"][@"advanced_pro_list"][@"list"]) {
            MZY_designerModel *designer = [[MZY_designerModel alloc]init];
            [designer setValuesForKeysWithDictionary:temp];
            [self.leftArr addObject:designer];
            [designer release];
        }
        [self.leftTableView reloadData];
    }];
    NSString *strR = [NSString stringWithFormat:@"http://api.meilijia.com/app/work_list?page=%ld&city_id=%@",self.pageTwo ++,self.idStr];
    [NetworkingTool networkingWithStrURL:strR type:GETType bodyStr:nil block:^(id result) {
        for (NSDictionary *temp in result[@"data"][@"work_list"][@"collections"]) {
            MZY_worksModel *works = [[MZY_worksModel alloc]init];
            [works setValuesForKeysWithDictionary:temp];
            [self.rightArr addObject:works];
            [works release];
        }
        [self.rightTableView reloadData];
    }];
    NSString *strF = [NSString stringWithFormat:@"http://api.meilijia.com/app/advanced_pro_gz_list?page=%ld&zone=%@",self.pageThree ++,self.idStr];
    [NetworkingTool networkingWithStrURL:strF type:GETType bodyStr:nil block:^(id result) {
        for (NSDictionary *temp in result[@"data"][@"advanced_pro_gz_list"][@"list"]) {
            MZY_designerModel *designer = [[MZY_designerModel alloc]init];
            [designer setValuesForKeysWithDictionary:temp];
            [self.foremanArr addObject:designer];
            [designer release];
            [self.foremanTableView reloadData];
        }
    }];
    NSString *strP = [NSString stringWithFormat:@"http://api.meilijia.com/app/pro_gz_work_list?page=%ld&city_id=%@",self.pageFour ++,self.idStr];
    [NetworkingTool networkingWithStrURL:strP type:GETType bodyStr:nil block:^(id result) {
        for (NSDictionary *temp in result[@"data"][@"pro_gz_work_list"][@"collections"]) {
            MZY_worksModel *works = [[MZY_worksModel alloc]init];
            [works setValuesForKeysWithDictionary:temp];
            [self.projectArr addObject:works];
            [works release];
        }
        [self.projectTableView reloadData];
    }];
}

#pragma mark 创建界面
- (void)createView{
    
    // 城市按钮
    self.leftButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.leftButton.frame = CGRectMake(0, 0, 80 * HORIZONTAL, 40 * VERTICAL);
    [self.leftButton setTitle:@"城市" forState:UIControlStateNormal];
    [self.leftButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [self.leftButton addTarget:self action:@selector(cityAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.leftButton];
    
    // 自定义标题
    UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"设计师",@"工长"]];
    seg.frame =CGRectMake(0, 100, 150, 30);
    seg.tintColor = [UIColor orangeColor];
    self.navigationItem.titleView = seg;
    [seg addTarget:self action:@selector(titleAction:) forControlEvents:UIControlEventValueChanged];
    seg.selectedSegmentIndex = 0;
    [seg release];
    
    // 分隔线
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 1)];
    textField.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:textField];
    [textField release];
    
    // 创建一个空白"view"
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 1, WIDTH, 30)];
    topView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:topView];
    [topView release];
    
    self.designerButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.designerButton.frame = CGRectMake(120 * HORIZONTAL, 0, 60, 30);
    [self.designerButton setTitle:@"找设计师" forState:UIControlStateNormal];
    [self.designerButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [topView addSubview:self.designerButton];
    [self.designerButton addTarget:self action:@selector(designerAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.worksButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.worksButton.frame = CGRectMake(220 * HORIZONTAL, 0, 80, 30);
    [self.worksButton setTitle:@"看设计作品" forState:UIControlStateNormal];
    [self.worksButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [topView addSubview:self.worksButton];
    [self.worksButton addTarget:self action:@selector(worksAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.isDesigner = NO;
    
    // 创建<设计师>"scrollView"
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 31, WIDTH  , HEIGHT - 64 - 49)];
    self.scrollView.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:self.scrollView];
    self.scrollView.contentOffset = CGPointMake(0, 0);
    self.scrollView.contentSize = CGSizeMake(WIDTH * 2, 0);
    self.scrollView.pagingEnabled = YES;
    self.scrollView.bounces = NO;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.delegate = self;
    [self.scrollView release];
    
    // 创建<设计师>左边的"tableView"
    self.leftTableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 10, WIDTH - 20, HEIGHT - 64 - 49 - 31) style:UITableViewStylePlain];
    self.leftTableView.backgroundColor = [UIColor cyanColor];
    self.leftTableView.rowHeight = 220 * HORIZONTAL;
    self.leftTableView.delegate = self;
    self.leftTableView.dataSource = self;
    [self.scrollView addSubview:self.leftTableView];
    [self.leftTableView registerClass:[MZY_DesignerCell class] forCellReuseIdentifier:@"left"];
    [self.leftTableView release];
    
    // 创建<设计师>右边的"tableView"
    self.rightTableView = [[UITableView alloc] initWithFrame:CGRectMake(WIDTH + 10, 10, WIDTH - 20, HEIGHT - 64 - 49 - 31) style:UITableViewStylePlain];
    self.rightTableView.backgroundColor = [UIColor cyanColor];
    self.rightTableView.rowHeight = 350 * HORIZONTAL;
    self.rightTableView.delegate = self;
    self.rightTableView.dataSource = self;
    [self.scrollView addSubview:self.rightTableView];
    [self.rightTableView registerClass:[MZY_worksCell class] forCellReuseIdentifier:@"right"];
    [self.rightTableView release];
    
    // 创建工长"view"
    self.foremanView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    self.foremanView.backgroundColor = [UIColor yellowColor];
    [self.foremanView release];
    
    // 分隔线
    UITextField *projectTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 1)];
    projectTextField.backgroundColor = [UIColor lightGrayColor];
    [self.foremanView addSubview:projectTextField];
    [projectTextField release];
    
    // 创建一个空白"view"
    UIView *projectTopView = [[UIView alloc] initWithFrame:CGRectMake(0, 1, WIDTH, 30)];
    projectTopView.backgroundColor = [UIColor whiteColor];
    [self.foremanView addSubview:projectTopView];
    [projectTopView release];
    
    self.foremanButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.foremanButton.frame = CGRectMake(120 * HORIZONTAL, 0, 60, 30);
    [self.foremanButton setTitle:@"找工长" forState:UIControlStateNormal];
    [self.foremanButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [projectTopView addSubview:self.foremanButton];
    [self.foremanButton addTarget:self action:@selector(designerAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.projectButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.projectButton.frame = CGRectMake(220 * HORIZONTAL, 0, 80, 30);
    [self.projectButton setTitle:@"看施工项目" forState:UIControlStateNormal];
    [self.projectButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [projectTopView addSubview:self.projectButton];
    [self.projectButton addTarget:self action:@selector(worksAction:) forControlEvents:UIControlEventTouchUpInside];

    
    // 创建<工长>"scrollView"
    self.foremanScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 31, WIDTH  , HEIGHT - 64 - 49)];
    self.foremanScrollView.backgroundColor = [UIColor cyanColor];
    [self.foremanView addSubview:self.foremanScrollView];
    self.foremanScrollView.contentOffset = CGPointMake(0, 0);
    self.foremanScrollView.contentSize = CGSizeMake(WIDTH * 2, 0);
    self.foremanScrollView.pagingEnabled = YES;
    self.foremanScrollView.bounces = NO;
    self.foremanScrollView.showsHorizontalScrollIndicator = NO;
    self.foremanScrollView.delegate = self;
    [self.foremanScrollView release];

    
    // 创建<工长>左边的"tableView"
    self.foremanTableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 10, WIDTH - 20, HEIGHT - 64 - 49 - 31) style:UITableViewStylePlain];
    self.foremanTableView.backgroundColor = [UIColor cyanColor];
//    self.foremanTableView.rowHeight = 220;
    self.foremanTableView.delegate = self;
    self.foremanTableView.dataSource = self;
    [self.foremanScrollView addSubview:self.foremanTableView];
    [self.foremanTableView registerClass:[MZY_ForemanCell class] forCellReuseIdentifier:@"foreman"];
    [self.foremanTableView registerClass:[MZY_WithoutPicture class] forCellReuseIdentifier:@"without"];
    [self.foremanTableView release];
    
    // 创建<工长>右边的"tableView"
    self.projectTableView = [[UITableView alloc] initWithFrame:CGRectMake(WIDTH + 10, 10, WIDTH - 20, HEIGHT - 64 - 49 - 31) style:UITableViewStylePlain];
    self.projectTableView.backgroundColor = [UIColor cyanColor];
    self.projectTableView.rowHeight = 350;
    self.projectTableView.delegate = self;
    self.projectTableView.dataSource = self;
    [self.foremanScrollView addSubview:self.projectTableView];
    [self.projectTableView registerClass:[MZY_ProjectCell class] forCellReuseIdentifier:@"project"];
    [self.projectTableView release];
    
    // 加载动画
    self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    self.pageOne = 2;
    self.pageTwo = 2;
    self.pageThree = 2;
    self.pageFour = 2;
    self.idStr = @"";
    // 下拉刷新
    [self.leftTableView addHeaderWithTarget:self action:@selector(refreshView)];
    self.leftTableView.headerRefreshingText = @"松开即可刷新";
    [self.rightTableView addHeaderWithTarget:self action:@selector(refreshView)];
    self.rightTableView.headerRefreshingText = @"松开即可刷新";
    [self.foremanTableView addHeaderWithTarget:self action:@selector(refreshView)];
    self.foremanTableView.headerRefreshingText = @"松开即可刷新";
    [self.projectTableView addHeaderWithTarget:self action:@selector(refreshView)];
    self.projectTableView.headerRefreshingText = @"松开即可刷新";
    // 上拉加载
    [self.leftTableView addFooterWithTarget:self action:@selector(loadDataView)];
    self.leftTableView.footerRefreshingText = @"请耐心等待,正在为您加载...";
    [self.rightTableView addFooterWithTarget:self action:@selector(loadDataView)];
    self.rightTableView.footerRefreshingText = @"请耐心等待,正在为您加载...";
    [self.foremanTableView addFooterWithTarget:self action:@selector(loadDataView)];
    self.foremanTableView.footerRefreshingText = @"请耐心等待,正在为您加载...";
    [self.projectTableView addFooterWithTarget:self action:@selector(loadDataView)];
    self.projectTableView.footerRefreshingText = @"请耐心等待,正在为您加载...";
}

#pragma mark 执行刷新
- (void)refreshView{
    [self createData];
    [self.leftTableView reloadData];
    [self.rightTableView reloadData];
    [self.foremanTableView reloadData];
    [self.projectTableView reloadData];
    [self.leftTableView headerEndRefreshing];
    [self.rightTableView headerEndRefreshing];
    [self.foremanTableView headerEndRefreshing];
    [self.projectTableView headerEndRefreshing];
}

#pragma mark 执行加载
- (void)loadDataView{
    [self loadData];
    [self.leftTableView reloadData];
    [self.rightTableView reloadData];
    [self.foremanTableView reloadData];
    [self.projectTableView reloadData];
    [self.leftTableView footerEndRefreshing];
    [self.rightTableView footerEndRefreshing];
    [self.foremanTableView footerEndRefreshing];
    [self.projectTableView footerEndRefreshing];
}

#pragma mark "tableView"的第一个必须执行的方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.leftTableView == tableView) {
        return self.leftArr.count;
    }else if(self.rightTableView == tableView){
        return self.rightArr.count;
    }else if (self.foremanTableView == tableView){
        return self.foremanArr.count;
    }else{
        return self.projectArr.count;
    }
}

#pragma mark "tableView"的第二个必须执行的方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.leftTableView == tableView) {
        MZY_DesignerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"left" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellEditingStyleNone;
        MZY_designerModel *designer = self.leftArr[indexPath.row];
        [cell.authorImageView sd_setImageWithURL:[NSURL URLWithString:designer.user_face]];
        cell.authorImageView.layer.cornerRadius = 25 * HORIZONTAL;
        cell.authorImageView.layer.masksToBounds = YES;
        cell.titleLabel.text = designer.user_nick;
        cell.titleLabel.textColor = [UIColor orangeColor];
        cell.locationLabel.text = designer.location;
        cell.locationLabel.textColor = [UIColor lightGrayColor];
        cell.locationLabel.font = [UIFont systemFontOfSize:15];
        if (designer.pro_covers.count == 0) {
            cell.leftImageView.image = [UIImage imageNamed:@"iconfont-tupian.png"];
            cell.midLeftImageView.image = [UIImage imageNamed:@"iconfont-tupian.png"];
            cell.midRightImageView.image = [UIImage imageNamed:@"iconfont-tupian.png"];
            cell.rightImageView.image = [UIImage imageNamed:@"iconfont-tupian.png"];
        }else{
            [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:designer.pro_covers[0]]];
            [cell.midLeftImageView sd_setImageWithURL:[NSURL URLWithString:designer.pro_covers[1]]];
            [cell.midRightImageView sd_setImageWithURL:[NSURL URLWithString:designer.pro_covers[2]]];
            [cell.rightImageView sd_setImageWithURL:[NSURL URLWithString:designer.pro_covers[3]]];
        }
        NSString *min = designer.pro_price_min;
        NSString *max = designer.pro_price_max;
        cell.priceLabel.text = [NSString stringWithFormat:@"%@%@%@%@%@",@"￥",min,@"-",max,@"/平米"];
        cell.priceLabel.textColor = [UIColor orangeColor];
        cell.priceLabel.backgroundColor = [UIColor greenColor];
        cell.priceLabel.alpha = 0.5;
        NSString *work = designer.verified_work_count;
        cell.worksLabel.text = [NSString stringWithFormat:@"%@%@%@",work,@" ",@"套已验证作品"];
        cell.worksLabel.font = [UIFont systemFontOfSize:15];
        cell.worksLabel.textAlignment = NSTextAlignmentRight;
        NSMutableAttributedString *workStr = [[NSMutableAttributedString alloc] initWithString:cell.worksLabel.text];
        [workStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];
        [workStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 2)];
        [cell.worksLabel setAttributedText:workStr];
        [workStr release];
        NSString *appointment = designer.contacted_count;
        cell.appointmentLabel.text = [NSString stringWithFormat:@"%@%@%@",appointment,@" ",@"人预约过"];
        cell.appointmentLabel.font = [UIFont systemFontOfSize:15];
        NSMutableAttributedString *appointmentStr = [[NSMutableAttributedString alloc] initWithString:cell.appointmentLabel.text];
        [appointmentStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];
        [appointmentStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 2)];
        [cell.appointmentLabel setAttributedText:appointmentStr];
        [appointmentStr release];
        return cell;
    }else if(self.rightTableView == tableView){
        MZY_worksCell *cell = [tableView dequeueReusableCellWithIdentifier:@"right" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        MZY_worksModel *works = self.rightArr[indexPath.row];
        [cell.pictureImageView sd_setImageWithURL:[NSURL URLWithString:works.cover_pic]];
        [cell.authorImageView sd_setImageWithURL:[NSURL URLWithString:works.author_face]];
        cell.authorImageView.layer.cornerRadius = 25 * HORIZONTAL;
        cell.authorImageView.layer.masksToBounds = YES;
        cell.titleLabel.text = works.title;
        cell.titleLabel.textColor = [UIColor orangeColor];
        cell.titleLabel.font = [UIFont systemFontOfSize:20];
        cell.introduceLabel.text = works.title_sub;
        cell.introduceLabel.textColor = [UIColor lightGrayColor];
        [cell.likeButton setImage:[UIImage imageNamed:@"zan.png"] forState:UIControlStateNormal];
        [cell.likeButton addTarget:self action:@selector(zanAction:) forControlEvents:UIControlEventValueChanged];
        cell.likeCountLabel.text = works.liked_count;
        cell.priceLabel.text = [NSString stringWithFormat:@"%@%@",works.work_design_price,@"元/平米"];
        cell.priceLabel.alpha = 0.6;
        return cell;
    }else if (self.foremanTableView == tableView){
        MZY_designerModel *designer = self.foremanArr[indexPath.row];
        if (designer.pro_covers.count != 0) {
            self.foremanTableView.rowHeight = 220 * HORIZONTAL;
            MZY_ForemanCell *cell = [tableView dequeueReusableCellWithIdentifier:@"foreman" forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellEditingStyleNone;
            [cell.authorImageView sd_setImageWithURL:[NSURL URLWithString:designer.user_face]];
            cell.authorImageView.layer.cornerRadius = 25;
            cell.authorImageView.layer.masksToBounds = YES;
            cell.titleLabel.text = designer.user_nick;
            cell.titleLabel.textColor = [UIColor orangeColor];
            cell.locationLabel.text = designer.location;
            cell.locationLabel.textColor = [UIColor lightGrayColor];
            cell.locationLabel.font = [UIFont systemFontOfSize:15];
            [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:designer.pro_covers[0]]];
            [cell.midLeftImageView sd_setImageWithURL:[NSURL URLWithString:designer.pro_covers[1]]];
            [cell.midRightImageView sd_setImageWithURL:[NSURL URLWithString:designer.pro_covers[2]]];
            [cell.rightImageView sd_setImageWithURL:[NSURL URLWithString:designer.pro_covers[3]]];
            NSInteger mark = [designer.pro_ratings_stars integerValue];
            if (mark == 0) {
                cell.oneStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid-2.png"];
                cell.twoStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid-2.png"];
                cell.threeStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid-2.png"];
                cell.fourStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid-2.png"];
                cell.fiveStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid-2.png"];
                cell.markLabel.text = designer.pro_ratings;
            }else if (mark == 4){
                NSInteger count = [designer.pro_ratings integerValue];
                if (count > 4.5) {
                    cell.oneStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                    cell.twoStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                    cell.threeStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                    cell.fourStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                    cell.fiveStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid-2.png"];
                    cell.markLabel.text = designer.pro_ratings;
                }else{
                    cell.oneStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                    cell.twoStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                    cell.threeStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                    cell.fourStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                    cell.fiveStarImageView.image = [UIImage imageNamed:@"iconfont-iconfontbankexing.png"];
                    cell.markLabel.text = designer.pro_ratings;
                }
            }else {
                cell.oneStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                cell.twoStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                cell.threeStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                cell.fourStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                cell.fiveStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                cell.markLabel.text = designer.pro_ratings;
            }
            cell.markLabel.textColor = [UIColor redColor];
            NSString *comment = designer.review_count;
            cell.commentLabel.text = [NSString stringWithFormat:@"%@%@",comment,@"条评论"];
            cell.commentLabel.textColor = [UIColor lightGrayColor];
            cell.commentLabel.font = [UIFont systemFontOfSize:15];
            NSString *work = designer.verified_work_count;
            cell.worksLabel.text = [NSString stringWithFormat:@"%@%@%@",work,@"  ",@"个已验证项目"];
            cell.worksLabel.font = [UIFont systemFontOfSize:15];
            cell.worksLabel.textAlignment = NSTextAlignmentRight;
            NSMutableAttributedString *workStr = [[NSMutableAttributedString alloc] initWithString:cell.worksLabel.text];
            [workStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];
            [workStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 2)];
            [cell.worksLabel setAttributedText:workStr];
            [workStr release];
            NSString *appointment = designer.contacted_count;
            cell.appointmentLabel.text = [NSString stringWithFormat:@"%@%@%@",appointment,@"  ",@"人预约过"];
            cell.appointmentLabel.font = [UIFont systemFontOfSize:15];
            NSMutableAttributedString *appointmentStr = [[NSMutableAttributedString alloc] initWithString:cell.appointmentLabel.text];
            [appointmentStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 3)];
            [appointmentStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 3)];
            [cell.appointmentLabel setAttributedText:appointmentStr];
            [appointmentStr release];
            return cell;
        }else{
            self.foremanTableView.rowHeight = 120 * HORIZONTAL;
            MZY_WithoutPicture *cell = [tableView dequeueReusableCellWithIdentifier:@"without" forIndexPath:indexPath];
            [cell.authorImageView sd_setImageWithURL:[NSURL URLWithString:designer.user_face]];
            cell.authorImageView.layer.cornerRadius = 25;
            cell.authorImageView.layer.masksToBounds = YES;
            cell.titleLabel.text = designer.user_nick;
            cell.titleLabel.textColor = [UIColor orangeColor];
            cell.locationLabel.text = designer.location;
            cell.locationLabel.textColor = [UIColor lightGrayColor];
            cell.locationLabel.font = [UIFont systemFontOfSize:15];
            NSInteger mark = [designer.pro_ratings_stars integerValue];
            if (mark == 0) {
                cell.oneStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid-2.png"];
                cell.twoStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid-2.png"];
                cell.threeStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid-2.png"];
                cell.fourStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid-2.png"];
                cell.fiveStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid-2.png"];
                cell.markLabel.text = designer.pro_ratings;
            }else if (mark == 4){
                NSInteger count = [designer.pro_ratings integerValue];
                if (count > 4.5) {
                    cell.oneStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                    cell.twoStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                    cell.threeStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                    cell.fourStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                    cell.fiveStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid-2.png"];
                    cell.markLabel.text = designer.pro_ratings;
                }else{
                    cell.oneStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                    cell.twoStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                    cell.threeStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                    cell.fourStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                    cell.fiveStarImageView.image = [UIImage imageNamed:@"iconfont-iconfontbankexing.png"];
                    cell.markLabel.text = designer.pro_ratings;
                }
            }else {
                cell.oneStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                cell.twoStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                cell.threeStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                cell.fourStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                cell.fiveStarImageView.image = [UIImage imageNamed:@"iconfont-star-solid.png"];
                cell.markLabel.text = designer.pro_ratings;
            }
            cell.markLabel.textColor = [UIColor redColor];
            NSString *comment = designer.review_count;
            cell.commentLabel.text = [NSString stringWithFormat:@"%@%@",comment,@"条评论"];
            cell.commentLabel.textColor = [UIColor lightGrayColor];
            cell.commentLabel.font = [UIFont systemFontOfSize:15];
            NSString *work = designer.verified_work_count;
            cell.worksLabel.text = [NSString stringWithFormat:@"%@%@%@",work,@"  ",@"个已验证项目"];
            cell.worksLabel.font = [UIFont systemFontOfSize:15];
            cell.worksLabel.textAlignment = NSTextAlignmentRight;
            NSMutableAttributedString *workStr = [[NSMutableAttributedString alloc] initWithString:cell.worksLabel.text];
            [workStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];
            [workStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 2)];
            [cell.worksLabel setAttributedText:workStr];
            [workStr release];
            NSString *appointment = designer.contacted_count;
            cell.appointmentLabel.text = [NSString stringWithFormat:@"%@%@%@",appointment,@"  ",@"人预约过"];
            cell.appointmentLabel.font = [UIFont systemFontOfSize:15];
            NSMutableAttributedString *appointmentStr = [[NSMutableAttributedString alloc] initWithString:cell.appointmentLabel.text];
            [appointmentStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 3)];
            [appointmentStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 3)];
            [cell.appointmentLabel setAttributedText:appointmentStr];
            [appointmentStr release];
            return cell;
        }
    }else{
        MZY_ProjectCell *cell = [tableView dequeueReusableCellWithIdentifier:@"project" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        MZY_worksModel *works = self.projectArr[indexPath.row];
        [cell.pictureImageView sd_setImageWithURL:[NSURL URLWithString:works.cover_pic]];
        [cell.authorImageView sd_setImageWithURL:[NSURL URLWithString:works.author_face]];
        cell.authorImageView.layer.cornerRadius = 25;
        cell.authorImageView.layer.masksToBounds = YES;
        cell.titleLabel.text = works.title;
        cell.titleLabel.textColor = [UIColor orangeColor];
        cell.titleLabel.font = [UIFont systemFontOfSize:20];
        cell.introduceLabel.text = works.title_sub;
        cell.introduceLabel.textColor = [UIColor lightGrayColor];
        [cell.likeButton setImage:[UIImage imageNamed:@"zan.png"] forState:UIControlStateNormal];
        [cell.likeButton addTarget:self action:@selector(zanAction:) forControlEvents:UIControlEventValueChanged];
        cell.likeCountLabel.text = works.liked_count;
        cell.priceLabel.text = works.cost_total_text;
        cell.priceLabel.alpha = 0.6;
        return cell;
    }
}

#pragma mark "tableView"的点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.leftTableView == tableView) {
        self.hidesBottomBarWhenPushed = YES;
        MZY_designerModel *design = self.leftArr[indexPath.row];
        MZY_EX_designerViewController *designerVC = [[MZY_EX_designerViewController alloc]init];
        [self.navigationController pushViewController:designerVC animated:YES];
        designerVC.idStr = design.user_id;
        self.hidesBottomBarWhenPushed = NO;
    }else if(self.rightTableView == tableView){
        self.hidesBottomBarWhenPushed = YES;
        MZY_EX_projectViewController *projectVC = [[MZY_EX_projectViewController alloc]init];
        [self.navigationController pushViewController:projectVC animated:YES];
        MZY_worksModel *work = self.rightArr[indexPath.row];
        projectVC.idStr = work.ID;
        self.hidesBottomBarWhenPushed = NO;
    }else if (self.foremanTableView == tableView){
        self.hidesBottomBarWhenPushed = YES;
        MZY_EX_foremanViewController *foremanVC = [[MZY_EX_foremanViewController alloc]init];
        [self.navigationController pushViewController:foremanVC animated:YES];
        MZY_designerModel *designer = self.foremanArr[indexPath.row];
        foremanVC.idStr = designer.user_id;
        self.hidesBottomBarWhenPushed = NO;
    }else{
        self.hidesBottomBarWhenPushed = YES;
        MZY_EX_workViewController *workVC = [[MZY_EX_workViewController alloc]init];
        [self.navigationController pushViewController:workVC animated:YES];
        MZY_worksModel *work = self.projectArr[indexPath.row];
        workVC.idStr = work.ID;
        self.hidesBottomBarWhenPushed = NO;
    }
}

#pragma mark "seg"的点击方法
- (void)titleAction:(UISegmentedControl *)seg{
    NSInteger index = seg.selectedSegmentIndex;
    switch (index) {
        case 0:
            [self.foremanView removeFromSuperview];
            break;
        case 1:
            [self.view addSubview:self.foremanView];
            break;
        default:
            break;
    }
}

#pragma mark 找设计师"button"的点击方法
- (void)designerAction:(UIButton *)button{
    if (self.isDesigner == NO) {
        self.scrollView.contentOffset = CGPointMake(0, 0);
        [self.designerButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [self.worksButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        self.foremanScrollView.contentOffset = CGPointMake(0, 0);
        [self.foremanButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [self.projectButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    }
    else{
        [self.designerButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [self.worksButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [self.foremanButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [self.projectButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    }
}

#pragma mark 看设计作品"button"的点击方法
- (void)worksAction:(UIButton *)button{
    if (self.isDesigner == NO) {
        self.scrollView.contentOffset = CGPointMake(WIDTH, 0);
        [self.designerButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [self.worksButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        self.foremanScrollView.contentOffset = CGPointMake(WIDTH, 0);
        [self.foremanButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [self.projectButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    }
    else{
        [self.designerButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [self.worksButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [self.foremanButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [self.projectButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    }
}

#pragma mark 根据偏移量切换"button"方法
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    if (self.scrollView == scrollView) {
        if (self.scrollView.contentOffset.x / WIDTH == 0) {
            [self.designerButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
            [self.worksButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        }else{
            [self.designerButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
            [self.worksButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        }
    }else{
        if (self.foremanScrollView.contentOffset.x / WIDTH == 0) {
            [self.foremanButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
            [self.projectButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        }else{
            [self.foremanButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
            [self.projectButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        }
    }
}


#pragma mark 赞"button"的点击方法
- (void)zanAction:(UIButton *)button{
    
}

#pragma mark 城市按钮点击方法
- (void)cityAction:(UIButton *)button{
    self.hidesBottomBarWhenPushed = YES;
    MZY_City *cityVC = [[MZY_City alloc]init];
    [self.navigationController pushViewController:cityVC animated:YES];
    void (^block)(NSString *) = ^(NSString *str){
        [self.leftButton setTitle:str forState:UIControlStateNormal];
    };
    cityVC.block = block;
    cityVC.delegate = self;
    
    self.hidesBottomBarWhenPushed = NO;
}

#pragma mark 传"id"
- (void)bringIdStr:(NSString *)idStr{
    self.idStr = idStr;
    NSString *firstStr = [NSString stringWithFormat:@"http://api.meilijia.com/app/advanced_pro_list?page=1&zone=%@",idStr];
    [NetworkingTool networkingWithStrURL:firstStr type:GETType bodyStr:nil block:^(id result) {
        self.leftArr = [NSMutableArray array];
        for (NSDictionary *temp in result[@"data"][@"advanced_pro_list"][@"list"]) {
            MZY_designerModel *designer = [[MZY_designerModel alloc]init];
            [designer setValuesForKeysWithDictionary:temp];
            [self.leftArr addObject:designer];
            [designer release];
        }
        [self.leftTableView reloadData];
        self.hud.hidden = YES;
    }];
    NSString *secondStr = [NSString stringWithFormat:@"http://api.meilijia.com/app/work_list?page=1&city_id=%@",idStr];
    [NetworkingTool networkingWithStrURL:secondStr type:GETType bodyStr:nil block:^(id result) {
        self.rightArr = [NSMutableArray array];
        for (NSDictionary *temp in result[@"data"][@"work_list"][@"collections"]) {
            MZY_worksModel *works = [[MZY_worksModel alloc]init];
            [works setValuesForKeysWithDictionary:temp];
            [self.rightArr addObject:works];
            [works release];
        }
        [self.rightTableView reloadData];
    }];
    NSString *thirdStr = [NSString stringWithFormat:@"http://api.meilijia.com/app/advanced_pro_gz_list?page=1&zone=%@",idStr];
    [NetworkingTool networkingWithStrURL:thirdStr type:GETType bodyStr:nil block:^(id result) {
        self.foremanArr = [NSMutableArray array];
        for (NSDictionary *temp in result[@"data"][@"advanced_pro_gz_list"][@"list"]) {
            MZY_designerModel *designer = [[MZY_designerModel alloc]init];
            [designer setValuesForKeysWithDictionary:temp];
            [self.foremanArr addObject:designer];
            [designer release];
            [self.foremanTableView reloadData];
        }
    }];
    NSString *fourthStr = [NSString stringWithFormat:@"http://api.meilijia.com/app/pro_gz_work_list?page=1&city_id=%@",idStr];
    [NetworkingTool networkingWithStrURL:fourthStr type:GETType bodyStr:nil block:^(id result) {
        self.projectArr = [NSMutableArray array];
        for (NSDictionary *temp in result[@"data"][@"pro_gz_work_list"][@"collections"]) {
            MZY_worksModel *works = [[MZY_worksModel alloc]init];
            [works setValuesForKeysWithDictionary:temp];
            [self.projectArr addObject:works];
            [works release];
        }
        [self.projectTableView reloadData];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
